﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DimensionData
{
    public class DimData
    {
        public int Level { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }

        public int Index { get; private set; }
        public int Range { get; private set; }
        public DimData Parent { get; private set; }

        public List<DimData> Children { get; set; }

        public DimData()
        {
            Children = new List<DimData>();
        }

        public DimData(string code, string name)
            : this()
        {
            Code = code;
            Name = name;
        }

        public DimData AddChild(DimData child)
        {
            child.Level = this.Level + 1;
            child.Index = this.Children.Count;
            child.Parent = this;
            this.Children.Add(child);
            this.AddRange();
            return child;
        }

        /// <summary>
        /// 范围加大
        /// </summary>
        protected void AddRange()
        {
            this.Range++;
            if (this.Parent != null)
            {
                this.Parent.AddRange();
            }
        }

        /// <summary>
        /// 范围减小
        /// </summary>
        protected void DelRange()
        {
        }
    }
}
